class Solution {
public:
    int missingNumber(vector<int>& nums) {
        int total = INT32_MIN;
        bool has_zero = false;
        for (int num : nums) {
            total = max(total, num);
            if (num == 0) {
                has_zero = true;
            }
        }
        int max_val = total;
        total = total * ((float) (total + 1) / 2);
        for (int num : nums) {
            total -= num;
        }
        if (total ==  0) {
            if (has_zero) {
                return max_val + 1;
            } else {
                return 0;
            }
        }
        return total;
    }
};